<template>
	<view>
		<newline></newline>

		<view class="login-tel">
			<view class="login-main">
				<view class="login-form">
					<view class="user">
						<text class="user-text">手机号:</text>
						<input type="number" focus="true" v-model="phone" placeholder="请输入11位手机号">
					</view>
				</view>
				<view class="logo-text" @tap="submit">
					下一步
				</view>
				<view class="reminder">
					温馨提示:手机号使用注意
				</view>
				<login></login>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from "@/common/api/request.js"
	import newline from "@/component/line.vue"
	export default {
		data() {
			return {
				phone: '',
				rules: {
					phone: {
						rule: /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/,
						msg: "请输入正确的手机号"
					}

				}
			}
		},
		methods: {
			submit() {

				if (!this.validate('phone')) return;
				uni.showLoading({
					title: "跳转中"
				})
				setTimeout(() => {
					uni.hideLoading();
				}, 2000)
				$http.request({
					url: "/register",
					method: "POST",
					data: {
						phone: this.phone
					},
				}).then((res) => {
					if (res.success) {
						uni.navigateTo({
							url: "/pages/login-code/login-code?phone="+this.phone+""
						})
						return;
					} else {
						uni.showToast({
							title: res.msg,
							icon: "error",
						})
					}

				}).catch(() => {})

			},
			validate(key) {
				let bool = true;
				if (!this.rules[key].rule.test(this[key])) {
					uni.showToast({
						title: this.rules[key].msg,
						icon: 'none'
					})
					bool = false;
					return false;
				}
				return bool;
			}
		},
		components: {
			newline
		}
	}
</script>

<style scoped>
	.logo-tel {
		width: 100vw;
		width: 100vh;
		line-height: 80rpx;
	}

	.logo-main {
		padding: 0 20rpx;
	}

	.login-form {
		padding: 30rpx 0;
	}

	.user {
		font-size: 32rpx;
		padding: 10rpx 0;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid #acacac;
	}

	.user-text {
		padding-right: 10rpx;
	}

	.reminder {
		color: #acacac;
		padding: 2rpx 0;
		text-align: center;
	}

	.logo-text {
		margin-bottom: 50rpx;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		color: white;
		background-color: #42B7FB;
		border-radius: 40rpx;
	}
</style>